import useGlobalAPI from '@/hooks/useGlobalAPI'
import {
  toStandardConfig,
  toAlarmConfig,
  toDeviceShare,
  toDevInfo,
  toFaultFeedback,
  toDevLog,
  toDataCollection,
  toSingleDevParams,
  toWarnEarlyConf
} from '@/libs/pageRedirect'
import {message} from 'ant-design-vue'
import {PropType} from 'vue'
import {IconImg} from '../image'
import {CnNormalSpan} from '../text'

export enum DevFunNameEnum {
  '0001' = '基本信息',
  '0002' = '分享设备',
  '0003' = '故障反馈',
  '0005' = '设备日志',
  '0009' = '采集频率',
  '0064' = '数据开关',
  '0075' = '合格标准',
  '0148' = '报警配置',
  '0149' = '产品资料'
}
export enum DevFunImgNameEnum {
  '0001' = 'devInfo',
  '0002' = 'shareDevice-sm',
  '0003' = 'faultFeedback',
  '0005' = 'devLog',
  '0009' = 'standard-sm',
  '0064' = 'paramSwitch',
  '0075' = 'standard-sm',
  '0148' = 'warnning-triangle-sm',
  '0149' = 'productFile-sm',
  '0252' = 'data-history-icon',
  '0256' = 'wran-icon'
}

export enum QuickFunNameEnum {
  '0165' = '标准配置',
  '0166' = '报警配置',
  '0167' = '设备分享',
  '0168' = '公司设置',
  '0169' = '手机换绑',
  '0170' = '产品资料',
  '0171' = '联系客服',
  '0187' = '大屏数据'
}
export enum QuickFunImgNameEnum {
  '0165' = 'standard',
  '0166' = 'warnning-triangle',
  '0167' = 'shareDevice',
  '0168' = 'company',
  '0169' = 'changePhone',
  '0170' = 'productFile',
  '0171' = 'contactUs',
  '0187' = 'screenDisplay',
  '0256' = 'wran_icon'
}

export const QuickUtilButton = defineComponent({
  props: {
    onClick: Function,
    dictCode: {
      type: String as PropType<QuickFunCode>,
      required: true
    }
  },
  setup(props, ctx) {
    const {router} = useGlobalAPI()

    function handleQiuickClick() {
      console.log(props.dictCode)

      switch (props.dictCode) {
        case '0165':
          router.push({
            path: '/CBC/standardConfig'
          })
          break
        case '0166':
          router.push({
            path: '/CBC/alarmConfig'
          })
          break
        case '0167':
          router.push({
            path: '/CBC/deviceShare'
          })
          break
        case '0167':
          router.push({
            path: '/CBC/deviceShare'
          })
          break
        case '0168':
          console.log('修改公司名称弹窗')
          break
        case '0169':
          console.log('修改手机号弹窗')
          break
        case '0170':
          console.log('产品资料')
          break
        case '0171':
          console.log('联系我们')
          break
        default:
          break
      }
    }

    return () => (
      <div
        class='w-64 h-64 flex flex-col justify-center items-center cursor-pointer'
        onClick={() => {
          if (props.onClick) {
            props.onClick()
          } else {
            handleQiuickClick()
          }
        }}
      >
        <IconImg
          imgName={QuickFunImgNameEnum[props.dictCode]}
          class='w-32 h-32 transition-all transform hover:opacity-105'
        ></IconImg>
        <CnNormalSpan class='text-12 text-text mt-4'>
          {QuickFunImgNameEnum[props.dictCode] || '---'}
        </CnNormalSpan>
      </div>
    )
  }
})

export const UtilButton = defineComponent({
  props: {
    onClick: Function,
    dictCode: {
      type: String as PropType<QuickFunCode>,
      required: true
    }
  },
  setup(props, ctx) {
    function handleQiuickClick() {
      switch (props.dictCode) {
        default:
          break
      }
    }

    return () => (
      <div
        class='w-64 h-64 flex flex-col justify-center items-center cursor-pointer'
        onClick={() => {
          if (props.onClick) {
            props.onClick()
          } else {
            handleQiuickClick()
          }
        }}
      >
        <IconImg
          imgName={QuickFunImgNameEnum[props.dictCode]}
          class='w-32 h-32 transition-all transform hover:opacity-105'
        ></IconImg>
        <CnNormalSpan class='text-12 text-text mt-4'>
          {QuickFunNameEnum[props.dictCode] || '---'}
        </CnNormalSpan>
      </div>
    )
  }
})

export const UtilButtonLine = defineComponent({
  props: {
    onClick: Function,
    value: {
      type: Object as PropType<DeviceManagement.UtilData>,
      required: true
    },
    devInfo: Object
  },
  setup(props, ctx) {
    function handleQiuickClick() {
      console.log(props.value.devFunCode)

      switch (props.value.devFunCode) {
        // 跳转基本信息
        case '0001':
          console.log(props.devInfo, 'props.devInfo')

          toDevInfo(props.devInfo)
          break
        // 跳转分享设备
        case '0002':
          toDeviceShare()
          break
        // 跳转故障反馈
        case '0003':
          toFaultFeedback()
          break
        // 跳转设备日志
        case '0005':
          toDevLog({devId: props.devInfo.value.devId, devName: props.devInfo.value.devName})
          break
        // 跳转采集频率
        case '0009':
          toDataCollection({devId: props.devInfo.value.devId})
          break
        // 跳转数据开关
        case '0064':
          toDataCollection({devId: props.devInfo.value.devId})
          break
        // 跳转合格标准
        case '0075':
          toStandardConfig({devId: props.devInfo.value.devId, devName: props.devInfo.value.devName})
          break
        // 跳转报警配置
        case '0148':
          toAlarmConfig(props.devInfo)
          break
        // 跳转产品资料
        case '0149':
          message.warning('开发中...')
          break
        // 跳转历史数据
        case '0252':
          // console.log(props.devInfo.value.devId, 'props.devInfo')
          toSingleDevParams({
            devId: props.devInfo.value.devId
          })
          break
        // 跳转预警配置
        case '0256':
          toWarnEarlyConf({
            devId: props.devInfo.value.devId
          })
          break
        default:
          message.warning('开发中...')
          break
      }
    }

    return () => (
      <div
        class='w-full h-24 flex justify-center items-center cursor-pointer'
        onClick={() => {
          if (props.onClick) {
            props.onClick()
          } else {
            handleQiuickClick()
          }
        }}
      >
        <IconImg
          imgName={DevFunImgNameEnum[props.value.devFunCode]}
          class='w-24 h-24 transition-all transform hover:opacity-105'
        ></IconImg>
        <CnNormalSpan class='text-12 text-text ml-6'>
          {props.value.devFunName || '---'}
        </CnNormalSpan>
      </div>
    )
  }
})
